package com.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author 徒有琴
 */
@WebListener
public class SpringListener implements ServletContextListener {
    private  ClassPathXmlApplicationContext applicationContext;
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("SpringListener");
        applicationContext=new ClassPathXmlApplicationContext("spring-mybatis.xml");
        servletContextEvent.getServletContext().setAttribute("applicationContext",applicationContext);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        applicationContext.close();
    }
}
